package com.example.controller.admin;

import com.example.result.Result;
import com.example.service.ReporterService;
import com.example.vo.OrderReportVO;
import com.example.vo.SalesTop10ReportVO;
import com.example.vo.TurnoverReportVO;
import com.example.vo.UserReportVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import java.time.LocalDate;

/**
 * 1. @ClassDescription:
 * 2. @author: Z
 * 3. @date: 2024年05月18日 18:25
 */
@RestController
@Slf4j
@Api(tags = "数据报表相关接口")
@RequestMapping("/admin/report")
public class ReporterController {


    @Autowired
    private ReporterService reporterService;

    @ApiOperation("营业额统计")
    @GetMapping("/turnoverStatistics")
    public Result<TurnoverReportVO> turnoverStatistics(
            @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate begin,
            @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate end
    ){
        return Result.success(reporterService.getTurnoverStatistics(begin,end));
    }

    @ApiOperation("会员统计")
    @GetMapping("/userStatistics")
    public Result<UserReportVO> userStatistics(
            @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate begin,
            @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate end
    ){
        return Result.success(reporterService.getUserStatistics(begin,end));
    }

    @ApiOperation("订单统计")
    @GetMapping("/ordersStatistics")
    public Result<OrderReportVO> ordersStatistics(
            @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate begin,
            @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate end
    ){
        return Result.success(reporterService.getOrdersStatistics(begin,end));
    }

    @ApiOperation("top10排行")
    @GetMapping("/top10")
    public Result<SalesTop10ReportVO> top10(
            @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate begin,
            @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate end
    ){
        return Result.success(reporterService.getTop10(begin,end));
    }

    @ApiOperation("导出运营数据表")
    @GetMapping("/export")
    public void export(HttpServletResponse response){
        reporterService.exportBusinessData(response);
    }
}
